<template>
	<view>

		<view class="room_size">
			<view class="">
				<view class="size_title">
					退款类型
				</view>
				<view class="size_img">
					<picker mode="selector" range-key="name" :range="tuiList" @change="tuiChange">
						<input class="inputs" type="text" v-model="type_name" placeholder="请选择退款类型" :disabled="true" />
					</picker>
				</view>
			</view>
		</view>
		<view class="room_size">
			<view class="">
				<view class="size_title">
					退款照片
				</view>
				<view class="size_img">
					<view class="add_house" @tap="Chouse_hand">
						<image src="../../static/jia.png" mode=""></image>
					</view>
					<view class="handlist" v-for="(item,i) in HandList" :key="i" @tap="ClickImg(HandList)">
						<image class="img" :src="tool.img(item)" mode=""></image>
						<image @tap.stop="HandDel(i)" class="dels" src="../../static/delsss.png" mode=""></image>
					</view>
				</view>
			</view>
		</view>

		<view class="room_size">
			<view class="">
				<view class="size_title">
					备注
				</view>
				<view class="size_img">
					<textarea class="gui-textarea gui-bg-gray" style="width:680rpx; height:200rpx;padding-left: 20rpx;"
						v-model="remark" maxlength="-1" placeholder="请输入退款原因" />
				</view>
			</view>
		</view>

		<view class="block" style="width: 100%;height: 160rpx;">

		</view>

		<view class="staff_create">
			<view class="create_btn" @tap.stop="Submit">
				退款
			</view>
		</view>
	</view>
</template>

<script>
	import tool from '@/utils/tool.js'
	import HeaderUrl from '../../config.js'
	export default {
		data() {
			return {
				tool: tool,
				btnName: '',
				id: '',
				noClick: true,
				textareaVal: '',
				HandList: [], //手绘
				tuiList: [{
						"name": "仅退款",
						"type": "jin"
					},
					{
						"name": "退货退款",
						"type": "huo"
					}
				],
				type_name: '',
				type: '',
				order_id: '',
				remark: ''
			}
		},
		onLoad(options) {
			this.order_id = options.order_id
			console.log(this.order_id, "??")
		},
		methods: {
			tuiChange(e) {
				console.log(e)
				let index = e.detail.value
				this.type = this.tuiList[index].type
				this.type_name = this.tuiList[index].name
			},
			ClickImg(item) {
				this.$TOOL.ClickImg(item)
			},
			HandDel(i) { //手绘删除
				this.HandList.splice(i, 1)
			},
			Chouse_hand() { //手绘照片
				uni.chooseImage({
					success: (chooseImageRes) => {
						uni.showLoading({
							title: '正在上传'
						})
						const tempFilePaths = chooseImageRes.tempFilePaths;
						uni.uploadFile({
							url: HeaderUrl.siteroot + 'common/upload',
							filePath: tempFilePaths[0],
							name: 'file',
							header: {
								token: uni.getStorageSync('token'),
								zcode: HeaderUrl.zcode
							},
							success: (uploadFileRes) => {
								uni.hideLoading()
								this.HandList.push(JSON.parse(uploadFileRes.data).data.fullurl)
							}
						});
					}
				});
			},
			Submit() {
				if (!this.type) {
					uni.showToast({
						title: '退款类型不得为空',
						icon: 'none'
					})
					return
				}
				uni.showModal({
					title: '是否发起退款',
					content: '发起后等待后台审核，请耐心等待',
					success: (res) => {
						if (res.confirm) {
							this.$http.Post('uter/refund', {
								order_id: this.order_id,
								type: this.type,
								remark: this.remark,
								pimages: this.HandList
							}, (result) => {
								uni.hideLoading()
								uni.showToast({
									title: '请等待平台审核',
									icon: 'none'
								})
								setTimeout(res => {
									uni.navigateBack()
								}, 500)
							})
						} else {

						}
					}
				})
			}
		}
	}
</script>

<style lang="scss">
	page {
		background-color: #f7f8fa;
	}

	.block {
		width: 100%;
		height: 160rpx;
	}

	.staff_create {
		width: 100%;
		height: 160rpx;
		background-color: #fff;
		display: flex;
		justify-content: center;
		align-items: center;
		position: fixed;
		bottom: 0;
	}

	.create_btn {
		width: 94%;
		height: 90rpx;
		border-radius: 60rpx;
		color: #fff;
		display: flex;
		justify-content: center;
		align-items: center;
		background-color: #ef5350;
		font-size: 32rpx;
	}

	.room_size {
		width: 94%;
		border-radius: 12rpx;
		margin: 40rpx auto;
		border: 1px solid #fff;
		background-color: #fff;
	}

	.room_size>view {
		margin: 0 auto;
		width: 96%;
	}

	.size_title {
		padding-left: 20rpx;
		font-size: 32rpx;
		color: #222222;
		font-weight: Bold;
		margin-top: 32rpx;
	}

	.size_img {
		width: 100%;
		margin-top: 20rpx;
		margin-bottom: 40rpx;
		display: flex;
		flex-wrap: wrap;
		justify-content: space-between;
	}

	.size_img::after {
		content: "";
		width: 200rpx;
		height: 0;
	}

	.add_house {
		width: 200rpx;
		height: 200rpx;
		display: flex;
		justify-content: center;
		align-items: center;
		background-color: #ededed;
	}

	.add_house>image {
		width: 80rpx;
		height: 80rpx;
	}

	.handlist {
		position: relative;
		margin-bottom: 20rpx;
		width: 200rpx;
		height: 200rpx;
		border-radius: 4rpx;
	}

	.img {
		width: 100%;
		height: 100%;
	}

	.dels {
		right: 0rpx;
		top: 0;
		position: absolute;
		width: 50rpx;
		height: 50rpx;
		z-index: 999;
	}

	.inputs {
		padding-left: 20rpx;
	}
</style>